package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    @GetMapping("/list")
    public PageDTO<Item> getlist(@RequestParam("page") Integer page,@RequestParam("size") Integer size){
        return itemService.getlist(page,size);
    }

    @GetMapping("/{id}")
    public Item getItem(@PathVariable("id") Long id) {
        return itemService.getItem(id);
    }

    @PostMapping
    public void addItem(@RequestBody Item item) {
        int row = itemService.addItem(item);
        System.out.println("row = " + row);
    }

    //上下架
    @PutMapping("status/{id}/{status}")
    public void updateItemStatus(@PathVariable("id") Long id,@PathVariable("status")Integer status) {
        itemService.updateItemStatus(id, status);
    }

    //修改
    @PutMapping
    public void updateItem(@RequestBody Item item){
        itemService.updateItem(item);
    }

    @DeleteMapping("/{id}")
    public void deleteItem(@PathVariable("id") Long id) {
        itemService.deleteItem(id);
    }
}
